Our goal is to add some interactivity to a “volcano plot”:

library("plotly")
## Loading required package: ggplot2
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library("htmlwidgets")
diff_exp <- readRDS("widgets/diff_exp.rds")
p <- plot_ly(data = diff_exp, x = ~meanDiff, y = ~logp) %>%
    add_markers(
        text = diff_exp[["geneName"]],
        customdata = paste0("https://www.genecards.org/cgi-bin/carddisp.pl?gene=", diff_exp[["geneName"]]))
onRender(
    p, "
  function(el) {
    el.on('plotly_click', function(d) {
      var url = d.points[0].customdata;
      window.open(url);
    });
  }
")
## Warning: `arrange_()` is deprecated as of dplyr 0.7.0.
## Please use `arrange()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.

Session information

sessionInfo()
## R version 4.0.2 (2020-06-22)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Mojave 10.14.6
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
## 
## locale:
## [1] en_US.UTF-8/fr_FR.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] htmlwidgets_1.5.1 plotly_4.9.2.1    ggplot2_3.3.2    
## 
## loaded via a namespace (and not attached):
##  [1] pillar_1.4.6      compiler_4.0.2    tools_4.0.2       digest_0.6.25    
##  [5] jsonlite_1.7.0    evaluate_0.14     lifecycle_0.2.0   tibble_3.0.3     
##  [9] gtable_0.3.0      viridisLite_0.3.0 pkgconfig_2.0.3   rlang_0.4.7      
## [13] crosstalk_1.1.0.1 yaml_2.2.1        xfun_0.16         withr_2.2.0      
## [17] dplyr_1.0.2       stringr_1.4.0     httr_1.4.2        knitr_1.29       
## [21] generics_0.0.2    vctrs_0.3.2       grid_4.0.2        tidyselect_1.1.0 
## [25] glue_1.4.1        data.table_1.13.0 R6_2.4.1          rmarkdown_2.3    
## [29] purrr_0.3.4       tidyr_1.1.1       magrittr_1.5      scales_1.1.1     
## [33] ellipsis_0.3.1    htmltools_0.5.0   colorspace_1.4-1  stringi_1.4.6    
## [37] lazyeval_0.2.2    munsell_0.5.0     crayon_1.3.4